package service;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import org.hibernate.validator.util.GetClassLoader;

import db.DBConn;

import entities.ClassEntity;

public class ClassService {

	public static List<ClassEntity> getAllClass() throws SQLException{
		Connection conn = DBConn.getConn();
		Statement stmt = conn.createStatement();
		String sql = "select * from shop_goodsclass";
		List<ClassEntity> classList =  new ArrayList<ClassEntity>();
		
		ResultSet rs = stmt.executeQuery(sql);
		while(rs.next()){
			ClassEntity cls = new ClassEntity();
			cls.setId(rs.getInt("class_id"));
			cls.setName(rs.getString("class_name"));
			cls.setDesc(rs.getString("class_desc"));
			classList.add(cls);
		}
		rs.close();
		conn.close();
		
		return classList;
		
	}
	
	public static void main(String[] args) throws SQLException{
		System.out.println(getAllClass());
	}
	
}
